package net.sansi.v3correctserver.config.matrixloader;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * Created by Fang
 * create time : 2024/11/8
 * IDE : IntelliJ IDEA
 * <p>
 * double类型矩阵文件转换器
 */
@Slf4j
public class DoubleMatrixFileLoader extends MatrixFileLoaderBase<Double> {

    // 空值填充值
    public static double NULL_VALUE = -8456123479.1234781;

    public DoubleMatrixFileLoader() {
        super(1);
    }

    @Override
    int getItemSize(Double item) {
        return 1;
    }

    @Override
    int getItemBufferSize(Double item) {
        return Double.BYTES;
    }

    @Override
    int getItemBufferSize(int len) {
        return Double.BYTES;
    }

    @Override
    void saveItemBuffer(ByteBuffer buffer, Double item) throws IOException {
        buffer.putDouble(item == null ? NULL_VALUE : item);
    }

    @Override
    Double readItemBuffer(ByteBuffer buffer, int size) throws Exception {
        return buffer.getDouble();
    }
}
